package com.mes_for_xxxxxx.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mes_for_xxxxxx.entity.Processflow;
import com.mes_for_xxxxxx.entity.Processflowrouter;
import com.mes_for_xxxxxx.entity.common.PageInfo;
import com.mes_for_xxxxxx.entity.common.Result;
import com.mes_for_xxxxxx.service.IProcessflowrouterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 工艺流程路由表 前端控制器
 * </p>
 *
 * @author 179005
 * @since 2024-09-10
 */
@RestController
@RequestMapping("/processflowrouter")
public class ProcessflowrouterController {
    @Autowired
    private IProcessflowrouterService processflowrouterService;

    /**
     * 生产线管理--工艺流程--分页查询
     * @param pageInfo 分页信息
     * @return
     */
    @PostMapping("/page")
    public Result pagesRouter(@RequestBody PageInfo pageInfo){
        int pageNum = pageInfo.getPageNum();
        int pageSize = pageInfo.getPageSize();
        //todo 待补充条件查询
        Page<Processflowrouter>page=new Page<>(pageNum,pageSize);
        return Result.success(processflowrouterService.page(page, null));
    }

    /**
     * 生产线管理--工艺流程--修改工艺状态（禁用与启用中）
     * @return
     */
    @GetMapping("/status/{id}")
    public Result updStatus(@PathVariable Long id){
        return Result.success(processflowrouterService.updStatus(id));
    }

    /**
     * 根据工艺name查询旗下的工序
     * 接取生产任务--工作任务领取--工艺路线
     * @param routerName
     * @return
     */
    @GetMapping("/findByName/{routerName}")
    public Result findByRouteName(@PathVariable String routerName){
        return Result.success(processflowrouterService.listProcessByRouteName(routerName));
    }

    @GetMapping("/listName")
    public Result listName(){
        List<Processflowrouter> list = processflowrouterService.list();
        //Map<String, String> collect = list.stream().collect(Collectors.toMap(Processflowrouter::getRouterName, Processflowrouter::getRouterNumber));
        List<Processflowrouter> list1=new ArrayList<>();
        list.forEach(item->{
            Processflowrouter processflowrouter=new Processflowrouter();
            processflowrouter.setRouterName(item.getRouterName());
            processflowrouter.setRouterNumber(item.getRouterNumber());
            list1.add(processflowrouter);
        });
        return Result.success(list1);
    }
    /**
     * 根据工艺id查询旗下的工序
     * 接取生产任务--工作任务领取--工艺路线
     * @param routerNumber
     * @return
     */
    @GetMapping("/find/{routerNumber}")
    public Result findByRouteId(@PathVariable String routerNumber){

        return Result.success(processflowrouterService.listProcess(routerNumber));
    }
}
